<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>XXXX系统1</title>
	</head>
	<body>
		<div style="margin:10px 0;">
		<a href="#" onclick="getSelected()">GetSelected</a>
		<a href="#" onclick="getSelections()">GetSelections</a>
		<a href="#" onclick="selectRow()">SelectRow</a>
		<a href="#" onclick="selectRecord()">SelectRecord</a>
		<a href="#" onclick="unselectRow()">UnselectRow</a>
		<a href="#" onclick="clearSelections()">ClearSelections</a>
		<a href="#" onclick="resize()">Resize</a>
		<a href="#" onclick="mergeCells()">MergeCells</a>
	</div>
	<div style="background-color: #efeefe;text-align:left;width: 100%">   
	   <span style="font-size: 12px">用户名：</span>   
	    <input name="username" id="username">  
	    <span style="margin-left:10px;font-size: 12px">用户密码：</span>   
	     <input name="pwd" id="pwd">  
		    <input type="button" onclick="loadGrid()" value="查询" />   
	</div>
		<table id="list_data"></table>

		<%@include file="/common/jquery.jsp"%>
		<%@include file="/common/easyui.jsp"%>
		<script type="text/javascript">
		
		
    //页面加载
/*为loadGrid()添加参数
		var queryParams = $('#cxdm').datagrid('options').queryParams;
	    queryParams.who = who.value;
	    queryParams.type = type.value;
	    queryParams.searchtype = searchtype.value;
	    queryParams.keyword = keyword.value;
	    //重新加载datagrid的数据
	    $("#cxdm").datagrid('reload');*/
    </script>
    	<script>
    	var container;
    	
   		function loadGrid() {
            var queryParams = container.datagrid('options').queryParams;
		    queryParams.password = $("#pwd").val();
		    queryParams.username = $("#username").val();
		    //重新加载datagrid的数据
		    container.datagrid('reload');
        }
    	
    	
		$(function(){
		container = $('#list_data');
			container.datagrid({
 				title:'应用系统列表',           
				iconCls:'icon-save',
				loadMsg:'数据装载中......',
				width:'auto',
				height:'auto',
			//	height:380,
				//属性规定表格单元格中的内容不换行。
				nowrap: true,
				//True 就把行条纹化。（即奇偶行使用不同背景色）
				striped: true,
				collapsible:true,
				//本地筛选排序remoteSort:false,
				url : '${pageContext.request.contextPath}/user/queryUserJsonUserAction.action',
				//默认排序名 传到后台 sortName: 'id',
				//sortOrder: 'desc',
				//remoteSort: false,
				idField:'id',
				//固定列 不能显隐
				frozenColumns:[[
	                {field:'ck',checkbox:true},
	                {field:'id',title: '编号',align: 'center',width: 40,sortable:true}
				]],
				 columns:[[
					{field:'username',title: '用户名',align: 'center',width: 150,sortable:true,
						//添加超级链，并将来文号作为参数传入
						formatter:function(val,rec){
							//alert(rec.adviceid);
		                	return "<a href='jsp/proposal/psconsultview.jsp?id="+rec.id+"'>"+val+"</a>";
		               }
					},
					{field:'password',title: '用户密码',align: 'center',width: 180},
					{field:'createDate',title: '创建日期',align: 'center',width: 180,sortable:true}														
				]], 
				onHeaderContextMenu: function(e, field){
					e.preventDefault();
					if (!$('#tmenu').length){
						createColumnMenu();
					}
					$('#tmenu').menu('show', {
						left:e.pageX,
						top:e.pageY
					});
				},
				onSortColumn: function( sort, order){
				} ,
				pagination:true,
			//	rownumbers:true,
				toolbar:[{
					id:'btnadd',
					text:'添加管理员',
					iconCls:'icon-add',
					handler:function(){
						$('#btnsave').linkbutton('enable');
						window.location.href = "${pageContext.request.contextPath}/web/samples/addUser.jsp";
					}
				},
				{
					id:'btnaddtest',
					text:'弹出式',
					iconCls:'icon-add',
					handler:function(){
						$('#btnsave').linkbutton('enable');
						addWin();
					}
				},{
					id:'btncut',
					text:'Cut',
					iconCls:'icon-remove',
					handler:function(){
						$('#btnsave').linkbutton('enable');
						alert('cut')
					}
				},'-',{
					id:'btnsave',
					text:'Save',
					//disabled:true,
					iconCls:'icon-edit',
					handler:function(){
						$('#btnsave').linkbutton('disable');
						alert('save')
					}
				}]
			});

			var p = container.datagrid('getPager');      
			$(p).pagination({          
			 pageSize: 10,//每页显示的记录条数，默认为10           
			 pageList: [5,10,15],//可以设置每页记录条数的列表           
			 beforePageText: '第',//页数文本框前显示的汉字          
			 afterPageText: '页    共 {pages} 页',           
			 displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'        
				/*onBeforeRefresh:function(){             
				 $(this).pagination('loading');              
				alert('before refresh');             
				 $(this).pagination('loaded');          
				}*/     
			 }); 
		});
		
		
		
		
		function resize(){
			container.datagrid('resize', {
				width:700,
				height:400
			});
		}
		function getSelected(){
			var selected = container.datagrid('getSelected');
			if (selected){
				alert(selected.code+":"+selected.name+":"+selected.addr+":"+selected.col4);
			}
		}
		function getSelections(){
			var ids = [];
			var rows = container.datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].code);
			}
			alert(ids.join(':'));
		}
		function clearSelections(){
			container.datagrid('clearSelections');
		}
		function selectRow(){
			container.datagrid('selectRow',2);
		}
		function selectRecord(){
			container.datagrid('selectRecord','002');
		}
		function unselectRow(){
			container.datagrid('unselectRow',2);
		}
		function mergeCells(){
			container.datagrid('mergeCells',{
				index:2,
				field:'addr',
				rowspan:2,
				colspan:2
			});
		}
		
		function createColumnMenu(){
			var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
			var fields = container.datagrid('getColumnFields');
			
			for(var i=0; i<fields.length; i++){
				var opts = container.datagrid('getColumnOption', fields[i]);
				var select = $('<div iconCls="icon-ok"/>');
				select.attr('id', fields[i]);
				select.html(opts.title).appendTo(tmenu);
			}
			tmenu.menu({
				onClick: function(item){
					if (item.iconCls=='icon-ok'){
						container.datagrid('hideColumn', item.id);
						tmenu.menu('setIcon', {
							target: item.target,
							iconCls: 'icon-empty'
						});
					} else {
						container.datagrid('showColumn', item.id);
						tmenu.menu('setIcon', {
							target: item.target,
							iconCls: 'icon-ok'
						});
					}
				}
			});
		}
		
	function addWin() {
		$('body').append('<div id="myWindow" class="easyui-dialog" closed="true"></div>'); 
		$('#myWindow').window({
		title: "标题啊",
		width: 600,
		height: 400,
		content: '<iframe scrolling="yes" frameborder="0"  src="${pageContext.request.contextPath}/web/samples/add.jsp" style="width:100%;height:98%;"></iframe>', 
		modal: true,
		shadow: false,
		cache: false,
		closed: false,
		collapsible: false,
		resizable: true,
		minimizable: false,
		maximizable : true,
		//maximized: true,
		loadingMessage: '正在加载数据，请稍等片刻......'
		});
	}

	</script>
	</body>
</html>